package applicationFunction.socks.nwct;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Tunnel extends Thread {
    private InputStream tin;
    private OutputStream tout;

    Tunnel(InputStream in, OutputStream out) {
        tin = in;
        tout = out;
    }

    public void run() {
        byte[] b = new byte[1024];
        while (true) {
            try {
                int length = tin.read(b);
                if (length == -1) {
                    tin.close();
                    tout.close();
                    return;
                }
                tout.write(b,0,length);
            } catch (IOException e) {
                // actually exit from the thread
                return;
            }
        }
    }
}
